const path = require("path");

function resolve(dir) {
  return path.join(__dirname, dir);
}

module.exports = {
  publicPath: "./",
  configureWebpack: {
    resolve: {
      alias: {
        "@": resolve("src"),
      }
    }
  },
  chainWebpack: config => {
    config.module
      .rule("svg")
      .exclude.add(resolve("src/icons"))
      .end();
    config.module
      .rule("icons")
      .test(/\.svg$/)
      .include.add(resolve("src/icons"))
      .end()
      .use("svg-sprite-loader")
      .loader("svg-sprite-loader")
      .options({
        symbolId: "icon-[name]"
      })
      .end();
  },
  devServer: {
    hot: true,
    proxy: {
      // 匹配所有以api开头的请求路径
      "/api": {
        target: "http://124.223.39.21:8082",
        ws: true,
        changeOrigin: true,
        secure: false,
        // 把api替换掉
        pathRewrite: {
          "^/api": ""
        }
      }
    }
  }
};
